﻿using System.Threading;
using System.Threading.Tasks;
using SaiLing.Domain;
using SaiLing.Repository;

namespace SaiLing.SingleSignOn.Repository
{
    public class UnitOfWork : IUnitOfWork
    {

        private readonly IDatabaseFactory<ProjectDbContext> _databaseFactory;
        private BaseDbContext _dataContext;

        public UnitOfWork(IDatabaseFactory<ProjectDbContext> databaseFactory)
        {
            this._databaseFactory = databaseFactory;
        }

        protected BaseDbContext DataContext => _dataContext ?? (_dataContext = _databaseFactory.Get());

        public Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            return DataContext.SaveChangesAsync(cancellationToken);
        }
        
    }
}
